/*
 * CameraPreviewForm.h
 *
 *  Created on: Jun 24, 2011
 *      Author: MongKieu
 */
#ifndef CAMERACAPTUREPREVIEWFORM_H_
#define CAMERACAPTUREPREVIEWFORM_H_

#include <FBase.h>
#include <FGraphics.h>
#include <FUi.h>
#include <FApp.h>
#include <FMedia.h>
#include <FIo.h>
#include <FSystem.h>

#include"../inc/Ui/CameraPreview.h"
#include "../Utility/Downloader.h"
#define IDC_GOTO_MAIN			120

class CameraForm: public Osp::Ui::Controls::Form,
		public Osp::Ui::IActionEventListener,
		public Osp::Media::ICameraEventListener,
		public IDownloadFinishedListener {
public:
	CameraForm(void);
	virtual ~CameraForm(void);
	void OnActionPerformed(const Osp::Ui::Control& source, int actionId);
	void OnCameraAutoFocused(bool completeCondition);
	void OnCameraPreviewed(Osp::Base::ByteBuffer& previewedData, result r);
	void OnCameraCaptured(Osp::Base::ByteBuffer& capturedData, result r);
	void OnCameraErrorOccurred(Osp::Media::CameraErrorReason r);
public:
	result Construct(Osp::Ui::Controls::Frame *pFrame,
			Osp::Ui::Controls::Form *pMainForm,
			Osp::Ui::Orientation orientation);
	result InitButtons(Osp::Ui::Orientation orientation);
	result OnInitializing(void);
	result OnTerminating(void);


public:

	/*Start Camera Preview*/
	result __InitCamera(void);
	result __InitOverlayPanel(Osp::Ui::Orientation orientation);
	result __TerminateCamera(void);

	result Start(void);
	result Stop(void);
	result Cancel(void);
	bool IsStarted(void);
	//bool CleanUp(void);
	result OnDraw(void);

protected:
	void _GotoMainForm(void);
private:

	CameraPreview* __pCameraPreview;
	Osp::Ui::Controls::OverlayPanel* __pOverlayPanel;
	Osp::Graphics::Canvas* __pOverlayCanvas;
	Osp::Ui::Controls::Button *__pBackButton;
	int __oPanelWidth, __oPanelHeight;
	bool __isStarted;

	Osp::Ui::Orientation __orientation;
	Osp::Ui::Controls::Frame* __pFrame;
	Osp::Ui::Controls::Form* __pParentForm;
	Osp::Ui::Controls::Label*__pDiaDiem;
	Osp::Ui::Controls::Label*__pThoiTiet;

public:
	void OnDataDownloadComplete(int statusCode, Osp::Base::ByteBuffer *buffer){}
	void OnDownloadComplete(Osp::Base::String url, Osp::Base::String path);
	void OnDownloadFailed(Osp::Base::String url, Osp::Base::String path);
	void HienThiDiaDiemCameraVaDownloadThoiTiet();
	void HienThiThoiTietCamera();
	void YeuCauCapNhatThongTinDiaDiemVaThoiTiet(float lat, float lng);
};

#endif // CAMERACAPTUREPREVIEWFORM_H_
